package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.CheckingAccount;
import com.acme.bankapp.domain.bank.SavingAccount;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.Gender;

public class BankApplication {
	private static Bank bank = new Bank();

	public static void main(String[] args) {
		BankService.addClient( bank, new Client("Vasiliy Pupkin", Gender.MALE, new SavingAccount(200)) );
		BankService.addClient( bank, new Client("Anna Karenina", Gender.FEMALE, new SavingAccount(500)) );
		BankService.addClient( bank, new Client("Lizzy Bennet", Gender.FEMALE, new SavingAccount(1000)) );
		BankService.addClient( bank, new Client("Oleg Portnov", Gender.MALE, new SavingAccount(300)) );
		BankService.addClient( bank, new Client("Tereza Lisbon", Gender.FEMALE, new CheckingAccount(400, 100)) );
		printBalance();

		System.out.println();
		modifyBank();
		printBalance();
		
		System.out.println();
		BankService.printMaximumAmountToWithdraw(bank);
	}

	private static void modifyBank() {
		Client[] clients = bank.getClients();
		
		// after this all clients will have balance = 600
		clients[0].getAccount().deposit(400);
		clients[1].getAccount().deposit(100);
		clients[2].getAccount().withdraw(400);
		clients[3].getAccount().deposit(300);
		
		// this will not affect balance because balance = 600 < 601
		clients[0].getAccount().withdraw(601);
		
		// checking account test
		clients[4].getAccount().withdraw(350);
	}

	private static void printBalance() {
		Client[] clients = bank.getClients();
		for (Client client : clients) {
			System.out.printf("%s:\t%.2f%n",
					client.getClientSalutation(),
					client.getAccount().getBalance());
		}
	}
}